﻿using System.Windows;
using System.Windows.Input;
using Microsoft.ApplicationServer.Caching.AdminApi;

namespace MDCAdminTool.Commands
{
    public class StopCacheCluster : AsyncCommandBindingBase
    {
        public StopCacheCluster() : base()
        {
            Command = Application.Current.Resources["StopCacheCluster"] as ICommand;
        }

        protected override void OnExecuted( object sender , ExecutedRoutedEventArgs e )
        {
            var service = e.Parameter as ICacheCommand;
            if ( service != null ) service.Stop();
        }
        protected override void OnCanExecute( object sender , CanExecuteRoutedEventArgs e )
        {
            var service = e.Parameter as ICacheCommand;

            if ( service != null )
                if ( service.Status == ServiceStatus.Up ||  service.Status == ServiceStatus.Starting )
                    e.CanExecute = true;
        }
    }
}